function [ErrorRateMeans ErrorRates] = nFold(InputSet, N)
    % Function that computes the error-rate of the N-fold cross validation of
    % the inputSet on a training set randomly taken from the inputSet.
    [TrainSets TestSet] = createSets(InputSet, N);

    for k=1:50,
        for i=1:N-1
            classifier = knn(2,2, k, TrainSets(:,1:2, i), TrainSets(:,3:4, i));
            [Results Labels] = knnfwd(classifier,TestSet(:,1:2));
            mat = confmat(Results, TestSet(:,3:4));
            correct(k) = (mat(1,1) + mat(2,2)) / length(Results);
            ErrorRates(k, i) = 1-correct(k);
        end
        ErrorRateMeans(k) = mean(ErrorRates(k, :));
    end
end
